const merge = require('webpack-merge')
const tsImportPluginFactory = require('ts-import-plugin')

const VUE_APP_HEADER_TITLE = '舞蹈培训'
module.exports = {
  parallel: false,
  outputDir: './dist',
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  productionSourceMap: process.env.NODE_ENV == 'production' ? false : true,
  chainWebpack: (config) => {
    config.module
      .rule('ts')
      .use('ts-loader')
      .tap((options) => {
        options = merge(options, {
          transpileOnly: true,
          getCustomTransformers: () => ({
            before: [
              tsImportPluginFactory({
                libraryName: 'vant',
                libraryDirectory: 'lib',
                style: true
              })
            ]
          }),
          compilerOptions: {
            module: 'es2015'
          }
        })
        return options
      })

    config.plugin('define').tap((args) => {
      args[0].VUE_APP_HEADER_TITLE = JSON.stringify(VUE_APP_HEADER_TITLE)
      return args
    })
    // config
    //   .plugin('webpack-bundle-analyzer')
    //   .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
  }
}
